package com.sjp.utils;

import com.sjp.entity.Brand;
import com.sjp.entity.Cell;
import com.sjp.entity.Layer;
import com.sjp.entity.Map;

import java.awt.*;

public class MapUtils {
    public  static Map builderMap(Integer floorHeight){
        Map m =new Map();
        m.setFloorHeight(floorHeight);
//        for (int i = 1; i <= floorHeight; i++) {
//            Layer l1 = LayerUtils.builderLayer(6,6);
//            m.getList().add(l1);
//        }

        Layer l1 = LayerUtils.builderLayer(6,6);
        Layer l2 = LayerUtils.builderLayer(6,6);
        Layer l3 = LayerUtils.builderLayer(6,6);

        l3.setParent(l2);
        l2.setParent(l1);
        l1.setParent(null);

        m.getList().add(l1);
        m.getList().add(l2);
        m.getList().add(l3);
        return m;
    }
    public static  boolean compare(Brand brand,Layer layer){
        if (layer == null){
            return false;
        }
        Cell[][] cells = layer.getCells();
        for (int row = 0; row < cells.length; row++) {
            for (int col = 0; col < cells[row].length; col++) {
                Cell cell = cells[row][col];
                if (cell.getState()==1){
                    Rectangle temp = cell.getBrand().getBounds();
                    Rectangle rect = brand.getBounds();
                    boolean result = rect.intersects(temp);
                    if (result){
                        return result;
                    }
                }
            }
        }
        if (brand.getParent()!=null){
            return compare(brand,layer.getParent());
        }else {
            return false;
        }

    }


}
